package cn.com.taiji.oospub.wechat.common.util;

import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;

public class MessageUtil {


    public static String sendMsgCode(String mobile, Integer code) {
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI4G6hfiVamzyUnkxmmw6p", "olnhSV9098scnsmcpfMLt5rkpZB688");
        IAcsClient client = new DefaultAcsClient(profile);
        CommonRequest commonRequest = new CommonRequest();
        commonRequest.setSysMethod(MethodType.POST);
        commonRequest.setSysDomain("dysmsapi.aliyuncs.com");
        commonRequest.setSysVersion("2017-05-25");
        commonRequest.setSysAction("SendSms");
        commonRequest.putQueryParameter("RegionId", "cn-hangzhou");
        commonRequest.putQueryParameter("PhoneNumbers", mobile);
        commonRequest.putQueryParameter("SignName", "爱玛客中国");
        commonRequest.putQueryParameter("TemplateCode", "SMS_235794796");
        commonRequest.putQueryParameter("TemplateParam", "{\"code\":\"" + code + "\"}");
        try {
            CommonResponse commonResponse = client.getCommonResponse(commonRequest);
            JSONObject resultJson = JSONObject.parseObject(commonResponse.getData());
            return resultJson.getString("Code");
        } catch (ClientException e) {
            e.printStackTrace();
        }
        return "";
    }
}
